var eeui = app.requireModule('eeui');

const umengPush = app.requireModule("eeui/umengPush");

const storage = weex.requireModule("storage");

Vue.mixin({

	data() {
		return {
			globalData: {
				color: '#3EB4FF',
				APP_BASE_API: 'https://boot.rzico.com:8443',
				mchId: '10200',
				uuid: null,
				userInfo: null,
				token: null
			}
		}
	},
	created() {
		var _this = this
		let data = eeui.getVariate("globalData");
		// console.log(data);
		if (!this.isEmptyString(data)) {
			let globalData = JSON.parse(data);
			if (!this.isEmptyString(globalData.token)) {
				this.globalData = globalData;
			}
		}
		this.globalData.uuid = eeui.getImei()

		let dataStr = JSON.stringify(this.globalData);
		eeui.setVariate("globalData", dataStr)

		storage.getItem("globalData", function(e) {
			if (e.result == "success" && e.data != undefined && e.data != 'undefined') {
				if (!_this.isEmptyString(e.data)) {
					_this.globalData = JSON.parse(e.data);
					let dataStr = JSON.stringify(_this.globalData);
					eeui.setVariate("globalData", dataStr)
				}
			}

		})


	},
	methods: {
		//权限判断
		checkPermission(value) {
			if (value && value instanceof Array && value.length > 0) {
                var menus = []
				let menuStr = eeui.getVariate("menus");
				if (!this.isEmptyString(menuStr)) {
                    menus = menuStr
				}
				const permissionMenus = value
				if(menus!=null){
					const hasPermission = menus.some(menu => {
					      return permissionMenus.includes(menu)
					    })
					if (!hasPermission) {
						return false
					}
					return true
				}

			} else {
				return false
			}
		},
        setPermission(menus) {
			if (menus==null) {
				menus = []
			}else{
				 eeui.setVariate("menus",menus)
			}
		},
		getGlobalData() {
			let data = eeui.getVariate("globalData");
			if (!this.isEmptyString(data)) {
				let globalData = JSON.parse(data);
				if (!this.isEmptyString(globalData.token)) {
					this.globalData = globalData;
				}
			}
			return this.globalData;
		},
		setGlobalData(data) {
			this.globalData = data;
            // this.globalData.menus = null;
			let dataStr = JSON.stringify(this.globalData);
			eeui.setVariate("globalData", dataStr)
			storage.setItem("globalData", dataStr)
		}
	}

});
